/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.ufc.model;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Paulo Silva
 */
public class TarefaTableModel extends GenericTableModel<Tarefa> {

    private String[] columnNames = {"Código", "Descrição", "Status"};
    private List<Tarefa> tarefaList;

    public TarefaTableModel() {
        tarefaList = new ArrayList<Tarefa>();
    }

    public TarefaTableModel(List<Tarefa> tarefaList) {
        this();
        setData(tarefaList);
    }

    @Override
    public void setData(List<Tarefa> list) {
        this.tarefaList.clear();
        this.tarefaList.addAll(list);
        super.fireTableDataChanged();
    }

    @Override
    public Tarefa getValueAt(int row) {
        return tarefaList.get(row);
    }

    @Override
    public int indexOf(Tarefa entity) {
        return tarefaList.indexOf(entity);
    }

    @Override
    public void clear() {
        this.tarefaList.clear();
        fireTableDataChanged();
    }

    @Override
    public void remove(Tarefa entity) {
        tarefaList.remove(entity);
        super.fireTableDataChanged();
    }

    @Override
    public void add(Tarefa entity) {
        tarefaList.add(0, entity);
        super.fireTableDataChanged();
    }

    @Override
    public boolean contains(Tarefa entity) {
        return tarefaList.contains(entity);
    }

    @Override
    public List<Tarefa> list() {
        return tarefaList;
    }

    @Override
    public void updateItem(int idx, Tarefa entity) {
        tarefaList.set( idx, entity );
        super.fireTableDataChanged();
    }

    public int getRowCount() {
        return tarefaList.size();
    }

    public int getColumnCount() {
        return columnNames.length;  
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Tarefa tarefa = tarefaList.get( rowIndex );
        switch( columnIndex ) {
            case 0: return tarefa.getCodigo();
            case 1: return tarefa.getDescricao();
            case 2: return tarefa.getStatus();
        }
        return null;
    }

    public String getColumnName(int col) {
        return columnNames[col];
    }

    public String[] getColumnNames() {
        return columnNames;
    }
}
